package br.com.poliwar.model {
	import flash.events.EventDispatcher;
	/**
	 * ...
	 * @author Ricardo Teixeira
	 */
	public class AbsSubject extends EventDispatcher {
		
		private var observers:Vector.<IObserver>;
		
		public function AbsSubject() {
			this.observers = new Vector.<IObserver> ();
		}
		
		public function attach (observer:IObserver):Boolean {
			var index:int = this.observers.indexOf (observer);
			if (index != -1) {
				this.observers.push (observer);
			}
			return (index != -1);
		}
		
		public function detach (observer:IObserver):Boolean {
			var index:int = this.observers.indexOf (observer);
			if (index != -1) {
				this.observers.splice (index, 1);
			}
			return (index != -1);
		}
		
		public function notify ():void {
			for (var i:int = 0; i < this.observers.length; i++) {
				this.observers[i].update ();
			}
		}
	}

}